<template>
	<view class="container">
		<view class="list">
			<view class="item u-flex u-col-center u-row-between" v-for="(item,index) in shopList"
				:class="{on:findex == index}" :key="index" @click="change(item,index)">
				<view class="l" @click.stop="$pageTo(`/pages/index/shopData?id=${item.id}`)">
					<image src="@/static/image/shop.png" mode="aspectFill"></image>
					<text>查看详情>></text>
				</view>
				<view class="r">
					<view class="name">
						{{item.name}}
					</view>
					<view class="addr u-l-1">
						{{item.address}}
					</view>
					<view class="addr" v-if="item.distance">
						距您{{item.distance.toFixed(2)}}km
					</view>
				</view>
				<view class="c">
					<image src="@/static/image/c.png" mode="aspectFill"></image>
				</view>
			</view>
		</view>
		<view class="footer" @click="gotoOrder">
			<view class="btn">
				<view class="t">
					去点餐
				</view>
				<view class="p">
					Order Now
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				findex: 0,
				fid: '',
				shopList: [],
				page: 1,
				longitude: '',
				latitude: '',

			}
		},
		onLoad() {
			this.longitude = uni.getStorageSync("lng")
			this.latitude = uni.getStorageSync("lat")
			this.getHomeData()
		},
		methods: {
			getHomeData() {
				this.$http.post('/app/homes/shopList', {
					longitude: this.longitude,
					latitude: this.latitude,
					page: this.page
				}).then(res => {
					console.log(res)
					if (res.code == 0) {
						this.shopList = [...this.shopList, ...res.data.list]
						if (uni.getStorageSync('shopData')) {
							this.fid = JSON.parse(uni.getStorageSync('shopData')).id
							this.findex = this.shopList.findIndex(item => item.id == this.fid)
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						});
					}
				}).catch(err => {
					console.log('表单错误信息：', err);
				})
			},
			gotoOrder() {
				uni.switchTab({
					url: '/pages/index/orderFood'
				})
			},
			change(data, index) {
				this.findex = index
				this.fid = data.id
				uni.setStorageSync('shopData', JSON.stringify(data))
			}
		}
	}
</script>

<style lang="less" scoped>
	.container {
		padding: 20rpx 20rpx 150rpx 20rpx;

		.footer {
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			padding: 20rpx;
			z-index: 999;
			box-shadow: 0rpx -2rpx 4rpx 0rpx rgba(0, 0, 0, 0.2);
			background-color: #fff;

			.btn {
				width: 100%;
				height: 100rpx;
				line-height: 100rpx;
				background: #E51B00;
				border-radius: 50rpx;
				text-align: center;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				.t {
					font-size: 30rpx;
					font-weight: 600;
					color: #fff;
					height: 50rpx;
					line-height: 50rpx;
				}

				.p {
					font-size: 18rpx;
					color: #fff;
					height: 30rpx;
					line-height: 30rpx;
				}
			}
		}

		.list {
			.item {
				margin-bottom: 20rpx;
				background-color: #fff;
				border-radius: 20rpx;
				padding: 20rpx;
				position: relative;
				border: 2rpx solid #fff;

				.l {
					width: 140rpx;
					height: 156rpx;
					background: #FFFFFF;
					border-radius: 8rpx;
					border: 1rpx solid #D1D1D6;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;

					image {
						width: 120rpx;
						height: 100rpx;
					}

					text {

						height: 30rpx;
						line-height: 30rpx;

						font-size: 22rpx;
						color: #000000;
						text-align: center;

					}
				}

				.r {
					flex: 1;
					width: 1rpx;
					margin-left: 20rpx;

					.name {
						margin-bottom: 15rpx;
						line-height: 40rpx;
						font-family: PingFang SC, PingFang SC;

						font-size: 28rpx;
						color: #000000;
						line-height: 36rpx;
						text-align: left;
						font-style: normal;
						text-transform: none;
					}

					.addr {
						margin-bottom: 10rpx;
						line-height: 30rpx;

						font-size: 22rpx;
						color: #B1B1B1;
						text-align: left;

					}
				}

				.c {
					position: absolute;
					top: 0;
					right: 0;
					width: 60rpx;
					height: 48rpx;
					background: #E51B00;
					border-radius: 0rpx 20rpx 0rpx 20rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					display: none;

					image {
						width: 48rpx;
						height: 48rpx;
					}
				}
			}

			.on {
				border: 2rpx solid #E51B00;

				.c {
					display: flex;
				}
			}
		}
	}
</style>